from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-09 14:03:43.772601
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 09, Jan, 2022
Time: 14:03:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6588
Nobs: 531.000 HQIC: -48.0998
Log likelihood: 6154.67 FPE: 9.71419e-22
AIC: -48.3833 Det(Omega_mle): 8.21263e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389572 0.073293 5.315 0.000
L1.Burgenland 0.101177 0.043032 2.351 0.019
L1.Kärnten -0.113520 0.022173 -5.120 0.000
L1.Niederösterreich 0.178017 0.089470 1.990 0.047
L1.Oberösterreich 0.109575 0.088943 1.232 0.218
L1.Salzburg 0.269811 0.045389 5.944 0.000
L1.Steiermark 0.027469 0.059827 0.459 0.646
L1.Tirol 0.109530 0.048195 2.273 0.023
L1.Vorarlberg -0.076217 0.042627 -1.788 0.074
L1.Wien 0.010578 0.078959 0.134 0.893
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057090 0.160999 0.355 0.723
L1.Burgenland -0.041427 0.094526 -0.438 0.661
L1.Kärnten 0.040001 0.048707 0.821 0.412
L1.Niederösterreich -0.209501 0.196535 -1.066 0.286
L1.Oberösterreich 0.453791 0.195377 2.323 0.020
L1.Salzburg 0.286267 0.099704 2.871 0.004
L1.Steiermark 0.115670 0.131419 0.880 0.379
L1.Tirol 0.306760 0.105869 2.898 0.004
L1.Vorarlberg 0.021414 0.093636 0.229 0.819
L1.Wien -0.020859 0.173447 -0.120 0.904
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203193 0.037500 5.419 0.000
L1.Burgenland 0.092556 0.022017 4.204 0.000
L1.Kärnten -0.007561 0.011345 -0.666 0.505
L1.Niederösterreich 0.232684 0.045776 5.083 0.000
L1.Oberösterreich 0.162023 0.045507 3.560 0.000
L1.Salzburg 0.041182 0.023223 1.773 0.076
L1.Steiermark 0.024794 0.030610 0.810 0.418
L1.Tirol 0.083170 0.024659 3.373 0.001
L1.Vorarlberg 0.054828 0.021809 2.514 0.012
L1.Wien 0.114578 0.040399 2.836 0.005
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132493 0.037518 3.531 0.000
L1.Burgenland 0.039354 0.022028 1.787 0.074
L1.Kärnten -0.014654 0.011350 -1.291 0.197
L1.Niederösterreich 0.167515 0.045799 3.658 0.000
L1.Oberösterreich 0.335859 0.045530 7.377 0.000
L1.Salzburg 0.105834 0.023234 4.555 0.000
L1.Steiermark 0.107623 0.030625 3.514 0.000
L1.Tirol 0.092850 0.024671 3.764 0.000
L1.Vorarlberg 0.054249 0.021820 2.486 0.013
L1.Wien -0.021757 0.040419 -0.538 0.590
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.095802 0.071252 1.345 0.179
L1.Burgenland -0.041978 0.041833 -1.003 0.316
L1.Kärnten -0.046011 0.021556 -2.135 0.033
L1.Niederösterreich 0.148248 0.086978 1.704 0.088
L1.Oberösterreich 0.173518 0.086466 2.007 0.045
L1.Salzburg 0.280207 0.044125 6.350 0.000
L1.Steiermark 0.062400 0.058160 1.073 0.283
L1.Tirol 0.154566 0.046853 3.299 0.001
L1.Vorarlberg 0.095020 0.041439 2.293 0.022
L1.Wien 0.082337 0.076760 1.073 0.283
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.093001 0.055366 1.680 0.093
L1.Burgenland 0.019081 0.032506 0.587 0.557
L1.Kärnten 0.051935 0.016750 3.101 0.002
L1.Niederösterreich 0.186209 0.067586 2.755 0.006
L1.Oberösterreich 0.326578 0.067188 4.861 0.000
L1.Salzburg 0.039953 0.034287 1.165 0.244
L1.Steiermark -0.003230 0.045193 -0.071 0.943
L1.Tirol 0.125879 0.036407 3.458 0.001
L1.Vorarlberg 0.064243 0.032200 1.995 0.046
L1.Wien 0.097530 0.059646 1.635 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154660 0.067071 2.306 0.021
L1.Burgenland 0.010362 0.039378 0.263 0.792
L1.Kärnten -0.065433 0.020291 -3.225 0.001
L1.Niederösterreich -0.105928 0.081874 -1.294 0.196
L1.Oberösterreich 0.217415 0.081392 2.671 0.008
L1.Salzburg 0.050215 0.041536 1.209 0.227
L1.Steiermark 0.253380 0.054748 4.628 0.000
L1.Tirol 0.498315 0.044104 11.299 0.000
L1.Vorarlberg 0.066683 0.039008 1.709 0.087
L1.Wien -0.075674 0.072256 -1.047 0.295
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163906 0.074164 2.210 0.027
L1.Burgenland -0.006210 0.043543 -0.143 0.887
L1.Kärnten 0.063592 0.022437 2.834 0.005
L1.Niederösterreich 0.175062 0.090534 1.934 0.053
L1.Oberösterreich -0.070872 0.090000 -0.787 0.431
L1.Salzburg 0.207198 0.045929 4.511 0.000
L1.Steiermark 0.139353 0.060538 2.302 0.021
L1.Tirol 0.054193 0.048768 1.111 0.266
L1.Vorarlberg 0.146125 0.043133 3.388 0.001
L1.Wien 0.130476 0.079898 1.633 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.416392 0.043235 9.631 0.000
L1.Burgenland -0.005551 0.025384 -0.219 0.827
L1.Kärnten -0.020921 0.013080 -1.599 0.110
L1.Niederösterreich 0.197067 0.052778 3.734 0.000
L1.Oberösterreich 0.238872 0.052467 4.553 0.000
L1.Salzburg 0.038163 0.026775 1.425 0.154
L1.Steiermark -0.022139 0.035292 -0.627 0.530
L1.Tirol 0.089610 0.028430 3.152 0.002
L1.Vorarlberg 0.048552 0.025145 1.931 0.054
L1.Wien 0.023304 0.046578 0.500 0.617
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.032494 0.093641 0.159893 0.138090 0.080144 0.079838 0.022118 0.205236
Kärnten 0.032494 1.000000 -0.028661 0.133032 0.047413 0.082998 0.447746 -0.072250 0.093870
Niederösterreich 0.093641 -0.028661 1.000000 0.307024 0.126061 0.262072 0.062525 0.151975 0.276504
Oberösterreich 0.159893 0.133032 0.307024 1.000000 0.216730 0.291104 0.168292 0.132059 0.226680
Salzburg 0.138090 0.047413 0.126061 0.216730 1.000000 0.124615 0.080140 0.107580 0.127817
Steiermark 0.080144 0.082998 0.262072 0.291104 0.124615 1.000000 0.133176 0.099872 0.022730
Tirol 0.079838 0.447746 0.062525 0.168292 0.080140 0.133176 1.000000 0.061615 0.148350
Vorarlberg 0.022118 -0.072250 0.151975 0.132059 0.107580 0.099872 0.061615 1.000000 -0.008976
Wien 0.205236 0.093870 0.276504 0.226680 0.127817 0.022730 0.148350 -0.008976 1.000000